// 方式一
// 二分法查找
// 时间：108ms - 46%
function mySqrt(x) {
  if (x <= 1) {
    return x;
  }
  let start = 0;
  let end = x;
  let sqrt = -1;
  while (start <= end) {
    const mid = Math.floor((start + end) / 2);
    if (mid * mid <= x) {
      sqrt = mid;
      start = mid + 1;
    } else {
      end = mid - 1;
    }
  }
  return sqrt;
}

console.log(mySqrt(17));
